package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "套餐相关接口")
@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐
     * @param categoryId 分类id
     * @return 套餐列表
     */
    @ApiOperation(value = "根据分类id查询套餐")
    @ApiImplicitParam(name = "categoryId", value = "分类id", required = true, example = "1", paramType = "query", dataType = "long")
    @GetMapping("/list")
    @Cacheable(value = "setmealList", key = "#categoryId") // key: setmealList::10
    public Result<List<Setmeal>> getSetmealListByCategoryId(@RequestParam Long categoryId) {
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE); // 查询起售中的套餐
        List<Setmeal> setmealList = setmealService.getSetmealList(setmeal);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询包含的菜品列表
     * @param id 套餐id
     * @return 套餐列表
     */
    @ApiOperation(value = "根据套餐id查询包含的菜品列表")
    @ApiImplicitParam(name = "id", value = "套餐id", required = true, example = "1", paramType = "path", dataType = "long")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
        List<DishItemVO> list = setmealService.getDishItemById(id);
        return Result.success(list);
    }
}
